package common.splitpage.template;

import common.splitpage.Condition;
import common.splitpage.PageInfo;


public class PageTemplate extends BaseTemplate {
	
	private String context;
	
	public PageTemplate(String context) {
		this.context = context;
	}
	
	public String getHtml(PageInfo pageInfo,String path) {
		Condition condition = pageInfo.getCondition();
		if(condition == null) condition = new Condition();
		
		int pageCount = condition.getPageCount();
		int curPage = condition.getCurPage();

		StringBuffer sb = new StringBuffer(1000);
		if(condition.isFirst()) {
			sb.append("<a style='color:#4a566a;cursor:none;'>首页</a>"); 
		} else {
			sb.append("<a href='" + this.context + path + "&curPage=1'>首页</a>"); 
		}
		
		if(condition.isHasPrevious()) {
			sb.append("&nbsp;&nbsp;<a href='" + this.context + path + "&curPage=" + (curPage-1) + "'>上一页</a>&nbsp;&nbsp;|&nbsp;&nbsp;");
		} else {
			sb.append("&nbsp;&nbsp;<a style='color:#4a566a;cursor:none;'>上一页</a>&nbsp;&nbsp;|&nbsp;&nbsp;");
		}
		
		int i = curPage-5;
		if(i<1) i = 1;
		for(;i>0 && i<curPage+5 && i<=pageCount;i++) {
			if(i == curPage) {
				sb.append("<a style='color:#FE3101;cursor:none;'><b>" + i + "</b></a>&nbsp;&nbsp;|&nbsp;&nbsp;");
			} else {
				sb.append("<a href='" + this.context + path + "&curPage=" + i + "'><b>" + i + "</b></a>&nbsp;&nbsp;|&nbsp;&nbsp;");
			}
		}
		
		if(condition.isHasNext()) {
			sb.append("<a href='" + this.context + path + "&curPage=" + (curPage+1) + "'>下一页</a>");
		} else {
			sb.append("<a style='color:#4a566a;cursor:none;'>下一页</a>");
		}
		
		if(condition.isLast()) {
			sb.append("&nbsp;&nbsp;<a style='color:#4a566a;cursor:none;'>尾页</a>");
		} else {
			sb.append("&nbsp;&nbsp;<a href='" + this.context + path + "&curPage=" + pageCount + "'>尾页</a>");
		}
		return sb.toString();
	}
	

	
}
